require('./build/modifyMainfest.js')
const isRelease = process.env.NODE_ENV === 'release'
const isH5 = process.env.VUE_APP_PLATFORM === 'h5'
// const ossDomain = 'https://activity-oss.zmaxfilm.com'
console.log(process.env.NODE_ENV, isH5, isRelease)
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const TransformPages = require('uni-read-pages')
const { webpack } = new TransformPages()
module.exports = {
  transpileDependencies: ['uview-ui'],
  assetsDir: 'static',
  indexPath: 'mobile.html',
  publicPath: './',
  devServer: {
    port: 8083,
    open: true,
    proxy: {
      '/api': {
        timeout: 0,
        target: 'https://zmax-test-mapi.zmaxfilm.com',
        changeOrigin: true,
        secure: true,
        https: true,
        pathRewrite: {
          '^/api': '/api'
        }
      },
      '/temporary': {
        //中转页新上下文
        timeout: 0,
        target: 'https://zmax-test-mapi.zmaxfilm.com',
        changeOrigin: true,
        secure: true,
        https: true,
        pathRewrite: {
          '^/temporary': '/temporary'
        }
      }
    }
  },
  configureWebpack: (config) => {
    config.plugins.push(
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'aliasPath']
          })
          return JSON.stringify(tfPages.routes)
        }, true)
      })
    )
    if (isH5) {
      config.plugins.push(
        new CompressionWebpackPlugin({
          algorithm: 'gzip',
          test: /\.(js|css)$/,
          threshold: 20480, // 超过20kb的文件就压缩
          deleteOriginalAssets: false, // 不删除源文件
          minRatio: 0.8
        })
      )
    }
  }
}
